package com.star.warmwinter.module.user.ui;

import android.databinding.DataBindingUtil;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.star.tool.util.SizeUtils;
import com.star.warmwinter.R;
import com.star.warmwinter.common.BaseActivity;
import com.star.warmwinter.databinding.CommonLoginTelBinding;
import com.star.warmwinter.module.user.viewCtrl.ForgetPwdCtrl;
import com.star.warmwinter.module.user.viewCtrl.LoginCtrl;
import com.star.warmwinter.module.user.viewCtrl.RegisterCtrl;

/**
 * Author: blackbai11
 * Date: 2018/5/31
 * Description: 通用手机号登录逻辑页面(登录,注册,忘记密码)
 */
public class CommonLoginTelActivity extends BaseActivity {

    public static String LOGIN_TYPE_KEY = "login_type_key";             //类型key
    public static final int LOGIN_TYPE_REGISTER = 0;                    //注册
    public static final int LOGIN_TYPE_LOGIN = 1;                       //登陆
    public static final int LOGIN_TYPE_FORGET_PWD = 2;                  //忘记密码
    public static String FORGET_PWD_TEL = "forget_pwd_tel";             //忘记密码-手机号
    private CommonLoginTelBinding mBinding;

    @Override
    public void bindLayout() {
        setContentView(R.layout.common_login_tel);
        mBinding = DataBindingUtil.setContentView(this, R.layout.common_login_tel);
    }

    @Override
    public void doBusiness() {
        //设置手机图标大小
        Drawable drawable = getResources().getDrawable(R.mipmap.icon_phone);
        drawable.setBounds(0, 0, SizeUtils.dp2px( 20), SizeUtils.dp2px( 26));
        mBinding.tvNoticeTel.setCompoundDrawables(drawable, null, null, null);

        int type = getIntent().getIntExtra(LOGIN_TYPE_KEY, -1);
        String forgetPwdTel = getIntent().getStringExtra(FORGET_PWD_TEL);
        switch (type) {
            case LOGIN_TYPE_REGISTER:
                /**
                 * 理论上应由CommonLoginVM控制不同页面显示区别，但CommonLoginVM已因复用内聚了三个页面业务控制
                 * 所以这里用activity承担进来时UI显示区别，CommonLoginVM负责业务逻辑区别
                 * 注：xml绑定VM的控件将不能通过获取控件设置，所以分层将xml中无需绑定VM的控件直接在此显示
                 */
                mBinding.titleBar.setTitle("注册");
                mBinding.edTel.setHint("请输入...");
                mBinding.cbProtocol.setVisibility(View.VISIBLE);
                mBinding.tvProtocol.setVisibility(View.VISIBLE);
                mBinding.setCommonLoginCtrl(new RegisterCtrl(this));
                break;

            case LOGIN_TYPE_LOGIN:
                mBinding.titleBar.setTitle("登录");
                mBinding.setCommonLoginCtrl(new LoginCtrl(this));
                break;

            case LOGIN_TYPE_FORGET_PWD:
                mBinding.titleBar.setTitle("忘记密码");
                ForgetPwdCtrl commonLoginCtrl = new ForgetPwdCtrl(this);
                commonLoginCtrl.getCommonLoginVM().setPhone(forgetPwdTel);
                mBinding.setCommonLoginCtrl(commonLoginCtrl);
                break;
        }
    }
}
